﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Mvc;
using System.Web.Http;
using Newtonsoft.Json;
using Jw.Models;
using System.Net;
using System.Dynamic;
using Newtonsoft.Json.Linq;
using Jw.Web;
using Jw.Web.App_Start;

namespace Jw.Web.Areas.Sys.Controllers
{
    public class ConfigController : BaseController
    {
        //
        // GET: /Sys/Config/
        [MvcMenuFilter(false)]
        public ActionResult Index()
        {
            var themes = new List<dynamic>();
            themes.Add(new { text = "默认主题", value = "default" });
            themes.Add(new { text = "Gray", value = "gray" });
            themes.Add(new { text = "Bootstrap", value = "bootstrap" });
            //themes.Add(new { text = "black", value = "black" });
            themes.Add(new { text = "Metro", value = "metro" });
            themes.Add(new { text = "metro-blue", value = "metro-blue" });
            //ui-sunny metro-blue
            themes.Add(new { text = "ui-sunny", value = "ui-sunny" });
            var navigations = new List<dynamic>();
            navigations.Add(new { text = "横向菜单", value = "menubutton" });
            navigations.Add(new { text = "手风琴(2级)", value = "accordion" });
            navigations.Add(new { text = "树形结构", value = "tree" });

            var model = new
            {
                dataSource = new
                {
                    themes = themes,
                    navigations = navigations
                },
                form = new sys_userService().GetCurrentUserSettings()
            };

            return View(model);
        }
    }

    public class ConfigApiController : ApiController
    {
        // GET api/sys/config
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/sys/config/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/sys/config
        public void Post([FromBody]JObject value)
        {
            if (value == null)
                throw new HttpResponseException(
                    new HttpResponseMessage(HttpStatusCode.NotAcceptable) { Content = new StringContent("配置不可为空") });

            var service = new sys_userService();
            service.SaveCurrentUserSettings(value);
        }

        // PUT api/sys/config/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/sys/config/5
        public void Delete(int id)
        {
        }
    }
}
